#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__author__ = "Administrator"
__name__="thread_lock2"
__date__="2016/7/29"
__time__="14:19"
"""
# 加线程锁。
import threading
import time
num = 0
def run(n):
    time.sleep(1)
    global num

# 只锁操作部分，完成后要释放。
    lock.acquire()
    num+=1
    lock.release()

    time.sleep(0.01)
    print '%s\n' % num
lock = threading.Lock()

for i in range(100):
    t = threading.Thread(target=run,args=(i,))
    t.start()